﻿using AutoMapper;
using ERPSystem.Common.Domains.UserCommon;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using SixLabors.Fonts.Unicode;

namespace RBACWrite.API.Command.UserEmail
{
    public class UserEmailCreateHandler : IRequestHandler<UserEmailCreateCommand, Result>
    {
        private readonly IBaseRepository<User> _userRepository;
        private readonly IMapper _mapper;

        public UserEmailCreateHandler(IBaseRepository<User> userRepository, IMapper mapper)
        {
            _userRepository = userRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 邮箱登录添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(UserEmailCreateCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Added };
            var list = new User()
            {
                Email = request.Email,
                Code = request.Code,
                CreateTime = DateTime.Now,
                EndTime = DateTime.Now.AddMinutes(1)
            };
            result.Code = await _userRepository.Add(list);
            return result; 

        }
    }
}
